<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">
      <div class="table-page-search-wrapper" v-if="hasPerm('storageOther:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="入库编码">
                <a-input v-model="queryParam.otherStorageCode" allow-clear placeholder="请输入入库编码"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="供应商名称">
                <a-input v-model="queryParam.supplierName" allow-clear placeholder="请输入供应商名称"/>
              </a-form-item>
            </a-col>
            <!-- <template v-if="advanced">
              <a-col :md="8" :sm="24">
                <a-form-item label="备注">
                  <a-input v-model="queryParam.remark" allow-clear placeholder="请输入备注"/>
                </a-form-item>
              </a-col>
            </template> -->
            <a-col :md="8" :sm="24" >
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)" >查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
                <!-- <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a> -->
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false">
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :alert="true"
        :rowKey="(record) => record.id"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      >
        <template class="table-operator" slot="operator" v-if="hasPerm('storageOther:add')" >
          <a-button type="primary" v-if="hasPerm('storageOther:add')" icon="plus" @click="goToAddForm">新增其他入库</a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="goToViewForm(record)">查看</a>
        </span>
      </s-table>
    </a-card>
  </div>
</template>
<script>
  import { STable } from '@/components'
  import { storageOtherPage } from '@/api/modular/main/storage/other/storageOtherManage'
  export default {
    components: {
      STable
    },
    data () {
      return {
        // 高级搜索 展开/关闭
        advanced: false,
        // 查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '入库编码',
            align: 'center',
            width: 200,
            ellipsis: true,
            dataIndex: 'otherStorageCode'
          },
          {
            title: '供应商名称',
            align: 'center',
            width: 250,
            ellipsis: true,
            dataIndex: 'supplierName'
          },
          {
            title: '总数',
            align: 'center',
            width: 200,
            ellipsis: true,
            dataIndex: 'totalQty'
          },
          {
            title: '备注',
            align: 'center',
            ellipsis: true,
            dataIndex: 'remark'
          },
          {
            title: '更新人',
            align: 'center',
            width: 100,
            ellipsis: true,
            dataIndex: 'updateUserName'
          },
          {
            title: '更新时间',
            align: 'center',
            width: 150,
            ellipsis: true,
            dataIndex: 'updateTime'
          }
        ],
        tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return storageOtherPage(Object.assign(parameter, this.queryParam)).then((res) => {
            return res.data
          })
        },
        selectedRowKeys: [],
        selectedRows: []
      }
    },
    created () {
      if (this.hasPerm('storageOther:edit') || this.hasPerm('storageOther:delete')) {
        this.columns.push({
          title: '操作',
          align: 'center',
          width: 100,
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
          fixed: 'right'
        })
      }
    },
    activated () {
      this.$refs.table.refresh()
    },
    methods: {
      goToAddForm () {
        this.$router.push({ path: '/storageOtherForm/add' })
      },
      goToViewForm (record) {
        this.$router.push({
          path: '/storageOtherForm/view',
          query: {
            code: record.otherStorageCode
          }
        })
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      }
    }
  }
</script>
<style lang="less">
  .table-operator {
    margin-bottom: 18px;
  }
  button {
    margin-right: 8px;
  }
</style>
